<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            list-style: none;
        }
        
        li {
            cursor: pointer;
            float: left;
            width: 200px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            background-color: cornflowerblue;
        }
        
        div {
            width: 200px;
            height: 30px;
            background-color: #00bdff;
        }
        
        .list {
            display: none;
        }
    </style>
</head>

<body>
    <ul>
        <li>导航菜单</li>
        <li>导航菜单
            <div class="list">
                <div class="item">次级菜单</div>
                <div class="item">次级菜单</div>
                <div class="item">次级菜单</div>
            </div>
        </li>
        <li>导航菜单</li>
        <li>导航菜单</li>
        <li>导航菜单</li>
    </ul>
    <script>
        let lis = document.querySelectorAll('li')
        let items = document.querySelectorAll('.item')
        lis.forEach(function(li, index) {
            li.addEventListener('mouseenter', function() {
                li.style.backgroundColor = '#00bdff'
                console.log(111);
                if (this.children.length === 1) {
                    this.children[0].style.display = 'block'
                }

            })
            li.addEventListener('mouseleave', function() {
                li.style.backgroundColor = 'cornflowerblue'
                console.log(111);
                if (this.children.length === 1) {
                    this.children[0].style.display = 'none'
                }

            })
        })
    </script>
</body>

</html>